package org.crud4j.wicket.app;

import org.apache.wicket.Component;
import org.apache.wicket.application.IComponentInstantiationListener;
import org.crud4j.core.CrudService;
import org.crud4j.ejb3.StandaloneCrudService;
import org.crud4j.wicket.CrudServiceInjectable;

public class CrudServiceInjector implements IComponentInstantiationListener {

	static {
		StandaloneCrudService.registerProvider(new TestCrudBeanProvider());
	}

	private CrudService crudService = new StandaloneCrudService();

	public void onInstantiation(Component component) {
		if (CrudServiceInjectable.class.isAssignableFrom(component.getClass())) {
			CrudServiceInjectable injectable = (CrudServiceInjectable) component;
			injectable.setCrudService(crudService);
		}
	}

}
